package com.elvis.chat.utils.add;

import org.jivesoftware.smack.packet.Message;

public class MessageChatType {
    /** (Default) a normal text message used in email like interface. */
    public static final int MSG_TYPE_NORMAL = 0;

    /** a typically short text message used in line-by-line chat interfaces. */
    public static final int MSG_TYPE_CHAT = 1;

    /** a chat message sent to a groupchat server for group chats. */
    public static final int MSG_TYPE_GROUP_CHAT = 2;

    /** a text message to be displayed in scrolling marquee displays. */
    public static final int MSG_TYPE_HEADLINE = 3;

    /** indicates a messaging error.. */
    public static final int MSG_TYPE_ERROR = 4;

    /**
     * Private default constructor.
     */
    private MessageChatType() {
    }

    /**
     * Get the Message type from a Message packet.
     * @param MessageColumns the Message type
     * @return an int representing the Message type
     */
    public static int getMessageType(final Message message) {
	int res;
	switch (message.getType()) {
	    case chat:
		res = MSG_TYPE_CHAT;
		break;
	    case groupchat:
		res = MSG_TYPE_GROUP_CHAT;
		break;
	    case normal:
		res = MSG_TYPE_NORMAL;
		break;
	    // TODO gerer les message de type error
	    // this a little work around waiting for a better handling of error
	    // messages
	    case headline:
		res = MSG_TYPE_HEADLINE;
		break;
	    case error:
		res = MSG_TYPE_ERROR;
		break;
	    default:
		res = MSG_TYPE_NORMAL;
		break;
	}
	return res;
    }

    /**
     * Get the smack Message mode for a status.
     * @param type the status type in beem
     * @return the Message mode to use in Message packet or null if there is no mode to use
     */
    public static Message.Type getMessageTypeFrom(final int type) {
	Message.Type res;
	switch (type) {
	    case MSG_TYPE_CHAT:
		res = Message.Type.chat;
		break;
	    case MSG_TYPE_GROUP_CHAT:
		res = Message.Type.groupchat;
		break;
	    case MSG_TYPE_NORMAL:
		res = Message.Type.normal;
		break;
	    case MSG_TYPE_HEADLINE:
		res = Message.Type.headline;
		break;
	    case MSG_TYPE_ERROR:
		res = Message.Type.error;
		break;
	    default:
		res = Message.Type.chat;
		break;
	}
	return res;
    }
}
